from PyQt4 import QtGui, QtCore

from limber.componentparser import ComponentInfos


class TabbedViewDisplayer(QtGui.QTabWidget):

    def __init__(self, parent):
        super(TabbedViewDisplayer, self).__init__(parent)


    def add_view(self, view):
        '''Adds a view to the ViewDisplayer.'''

        title = view.title()
        self.addTab(view, title)

        view.title_changed.connect(self.update_view_titles)

    def close_view(self, view):
        '''Closes a view.'''

        index = self.indexOf(view)
        self.removeView(index)

    def update_view_titles(self):
        '''Updates all the views' titles.'''

        for view in self.widgets():
            title = view.title()
            self.setTabText(self.indexOf(view), title)

INFOS_DICT = {
    'name' : 'tabbedviewdisplayer',
    'full_name' : 'Tabbed View Displayer',
    'class_name' : 'TabbedViewDisplayer',
    'directory' : '../Widgets',
    'filename' : 'tabbedviewdisplayer.py',
    'version' : '0.1.0',
    'short_description' : 'A simple tab viewdisplayer.',
    'author' : 'Giacomo Alzetta',
    'interface' : 'viewdisplayer',
    'abilities' : 'TABBABLE_VIEW',
    }

COMPONENT_FILE_CONTENT = '''\
name = %(name)s
full_name = %(full_name)s
class_name = %(class_name)s
directory = %(directory)s
filename = %(filename)s
version = %(version)s
short_description = %(short_description)s
author = %(author)s
interface = %(interface)s
abilities = %(abilities)s
''' % INFOS_DICT

_better_infos = dict(INFOS_DICT)
_better_infos['abilities'] = INFOS_DICT['abilities'].split(':')

INFOS = ComponentInfos(**_better_infos)

del _better_infos
